<!DOCTYPE html>
<html>
	<head>
		<title>设置个人资料</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<script src="/js/plugins/jquery-form/jquery.form.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/myInfo.css" />
		<script>
			$(function () {
				var user = JSON.parse(window.sessionStorage.getItem("user"));
				$('.info').renderValues(user);
				$('.myBg').css('background-image',"url("+user.coverImgUrl+")");

				var flag;
				$('#headBtn').click(function () {
				    flag = 1;
					$('#image').click();
                });
				$('#coverBtn').click(function () {
				    flag = 2;
					$('#image').click();
                });

				$('#imageForm').change(function () {
                    if($('#image').val()){
                       $('#imageForm').ajaxSubmit(function (data) {
                          if(data.status == 1){
                              if(flag == 1){
                                  $('#headImg').prop('src',data.url);
                                  $('[name="headImgUrl"]').val(data.url);
							  }
							  if(flag == 2){
                                  $('.myBg').css('background-image',"url("+data.url+")");
                                  $('[name="coverImgUrl"]').val(data.url);
							  }

						  }
                       });
				   }
                });

				$('#saveBtn').click(function () {
					$('#infoForm').ajaxSubmit(function (data) {
					    if(data.success){
					        window.parent.location.href = '/index.html';
                            sessionStorage.clear();
                            window.sessionStorage.setItem("user",JSON.stringify(data.data));
                        } else{
                            $(document).dialog({
                                autoClose: 2000,
                                content: data.msg,
                            });
						}
                    });
                });

            });
		</script>
	</head>

	<body>
		<div class="search-head">
			<div class="row nav-search">
				<div class="col">
					<a href="javascript:window.history.go(-1);">
						<span>取消</span>
					</a>
				</div>
				<div class="col">
					<span>设置个人资料</span>
				</div>
				<div class="col" >
					<a href="javascript:;" id="saveBtn" >
						<span>保存</span>
					</a>
				</div>
			</div>
		</div>

		<div class="container info">


			<form action="/images" method="post" id="imageForm" enctype="multipart/form-data">
				<input type="file" name="file" id="image" hidden accept="image/*">
			</form>
			<div class="myBg">
				<img id="headImg" render-src="headImgUrl" class="rounded-circle"/>
				<div class="editHead" id="headBtn" ><i class="fa fa-pencil-square fa-lg " aria-hidden="true"></i></div>
				<button  class="btn btn-outline-light ibtn " id="coverBtn">设置背景</button>
			</div>

			<form id="infoForm" method="post" action="/users">
					<input render-value="id" type="hidden" name="id" >
					<input render-value="headImgUrl" type="hidden" name="headImgUrl" >
					<input render-value="coverImgUrl" type="hidden" name="coverImgUrl" >
					<input type="hidden" name="_method" value="PUT">
					<label>昵称</label><input type="text" render-value="nickName" name="nickName" class="form-control" >
					<label>性别</label><select class="form-control" name="gender" render-value="gender">
							<option value="-1">保密</option>
							<option value="0">男</option>
							<option value="1">女</option>
						</select>
					<label>地区</label><input type="text" name="place" render-value="place"  class="form-control">
					<label>签名</label><textarea name="sign" render-value="sign" class="form-control" rows="5" ></textarea>
			</form>
		</div>
		
		
		
	</body>
</html>
